|
1
|
|
|
import L from 'leaflet'; |
|
2
|
|
|
import marker2x from 'leaflet/dist/images/marker-icon-2x.png'; |
|
3
|
|
|
import marker from 'leaflet/dist/images/marker-icon.png'; |
|
4
|
|
|
import markerShadow from 'leaflet/dist/images/marker-shadow.png'; |
|
5
|
|
|
import { range } from 'ramda'; |
|
6
|
|
|
import { useState } from 'react'; |
|
7
|
|
|
|
|
8
|
14 |
|
const TEN_ROUNDING_NUMBER = 10; |
|
9
|
14 |
|
const DEFAULT_TIMEOUT_DELAY = 2000; |
|
10
|
14 |
|
const { ceil } = Math; |
|
11
|
|
|
|
|
12
|
14 |
|
export const stateFlagTimeout = (setTimeout) => ( |
|
13
|
|
|
setState, |
|
14
|
|
|
flagName, |
|
15
|
|
|
initialValue = true, |
|
16
|
|
|
delay = DEFAULT_TIMEOUT_DELAY |
|
17
|
|
|
) => { |
|
18
|
1 |
|
setState({ [flagName]: initialValue }); |
|
19
|
1 |
|
setTimeout(() => setState({ [flagName]: !initialValue }), delay); |
|
20
|
|
|
}; |
|
21
|
|
|
|
|
22
|
14 |
|
export const determineOrderDir = (clickedField, currentOrderField, currentOrderDir) => { |
|
23
|
11 |
|
if (currentOrderField !== clickedField) { |
|
24
|
4 |
|
return 'ASC'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
7 |
|
const newOrderMap = { |
|
28
|
|
|
ASC: 'DESC', |
|
29
|
|
|
DESC: undefined, |
|
30
|
|
|
}; |
|
31
|
|
|
|
|
32
|
7 |
|
return currentOrderDir ? newOrderMap[currentOrderDir] : 'ASC'; |
|
33
|
|
|
}; |
|
34
|
|
|
|
|
35
|
14 |
|
export const fixLeafletIcons = () => { |
|
36
|
1 |
|
delete L.Icon.Default.prototype._getIconUrl; |
|
37
|
|
|
|
|
38
|
1 |
|
L.Icon.Default.mergeOptions({ |
|
39
|
|
|
iconRetinaUrl: marker2x, |
|
40
|
|
|
iconUrl: marker, |
|
41
|
|
|
shadowUrl: markerShadow, |
|
42
|
|
|
}); |
|
43
|
|
|
}; |
|
44
|
|
|
|
|
45
|
14 |
|
export const rangeOf = (size, mappingFn, startAt = 1) => range(startAt, size + 1).map(mappingFn); |
|
46
|
|
|
|
|
47
|
14 |
|
export const roundTen = (number) => ceil(number / TEN_ROUNDING_NUMBER) * TEN_ROUNDING_NUMBER; |
|
48
|
|
|
|
|
49
|
14 |
|
export const useToggle = (initialValue = false) => { |
|
50
|
2 |
|
const [ flag, setFlag ] = useState(initialValue); |
|
51
|
|
|
|
|
52
|
2 |
|
return [ flag, () => setFlag(!flag) ]; |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
export const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)); |
|
56
|
|
|
|